package com.lanchewuyou.user.driver.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.lanchewuyou.user.driver.R;
import com.lanchewuyou.user.driver.bean.YancheFixItem;

import java.util.ArrayList;
import java.util.List;

/**
 * 验车列表适配器
 */
public class YancheFixAdapter extends BaseAdapter {

    private List<YancheFixItem> yancheFixItemList = new ArrayList<>();
    private LayoutInflater inflater;
    private Context mContext;

    public YancheFixAdapter(List<YancheFixItem> yancheFixItemList, Context mContext) {
        this.yancheFixItemList = yancheFixItemList;
        this.mContext = mContext;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return yancheFixItemList.size();
    }

    @Override
    public Object getItem(int position) {
        return yancheFixItemList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        YancheFixItem yancheFixItem = yancheFixItemList.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.yanche_fix_grid_item, null);
            viewHolder.yancheFixText = (TextView) convertView.findViewById(R.id.yanche_fix_item_text);
            viewHolder.yancheFrame = (FrameLayout) convertView.findViewById(R.id.yanche_fix_item_frame);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.yancheFixText.setText(yancheFixItem.getItemText());
        if (yancheFixItem.getPressType() == 0) {
            viewHolder.yancheFrame.setBackgroundResource(R.drawable.yanche_fix_item);
        } else{
            viewHolder.yancheFrame.setBackgroundResource(R.drawable.yanche_fix_item_press);
        }
        return convertView;
    }


    class ViewHolder {
        public TextView yancheFixText;
        public FrameLayout yancheFrame;
    }
}
